/**
 * Created by 王涛 on 2017/6/8.
 */
$(function () {
    //confirm 弹窗  start
    function confirmModel(title, body, okBtn, cancelBtn, okHidden) {
        if (!title) {
            title = '温馨提示';
        }
        if (!body) {
            body = '确定要删除吗？';
        }
        if (!okBtn) {
            okBtn = '确定';
        }
        if (!cancelBtn) {
            cancelBtn = '取消';
        }
        $.confirm({
            title: title,
            body: body,
            okBtn: okBtn,
            cancelBtn: cancelBtn,
            transition: true,
            okHidden: function () {
                okHidden();
            }
        });
    } //confirm 弹窗  end

    //alert 弹窗  start
    function alertModel(title, body) {
        if (!title) {
            title = '温馨提示';
        }
        if (!body) {
            body = '出错了，再来一次！';
        }
        $.alert({
            title: title,
            body: body,
            transition: true
        });
    } //alert 弹窗  end

    //保存下一步  切换标签页方法  start
    function saveNext() {
        var actived = $('#addCaseNavTabs').find('li.active');
        actived.removeClass('active');
        if (actived.next().find('a').hasClass('disabled')) {
            actived.next().next().addClass('active');
            var id = actived.next().next().find('a').attr('href');
            $(id).addClass('active').prev().prev().removeClass('active');
        } else {
            actived.next().addClass('active');
            var id = actived.next().find('a').attr('href');
            $(id).addClass('active').prev().removeClass('active');
        }
        scrollTo(0, 0);
        beforeGetData(actived.next().attr('data-href'));
    } //保存下一步  切换标签页方法  end

    //检测血糖值 start
    function checkBloodNum(arr) {
        for (var i = 0; i < arr.length; i++) {
            if (arr[i]) {
                if (isNaN(arr[i])) {
                    return false;
                }
                if (arr[i] <= 0 || arr[i] > 50) {
                    return false;
                }
            }
        }
        return true;
    }//检测血糖值 end


    //标签页添加浏览器记住事件  start
    $('#addCaseNavTabs li').click(function () {
        if (!($(this).find('a').hasClass('disabled'))) {
            var id = $(this).find('a').attr('href');
            sessionStorage.setItem('tabPage', id);
        }
    });
    var tabPage = sessionStorage.getItem('tabPage');
    if (tabPage) {
        $(tabPage).addClass('active').siblings().removeClass('active');
        $('#addCaseNavTabs li').find('a[href="' + tabPage + '"]').parent().addClass('active').siblings().removeClass('active');
    }
    //标签页添加浏览器记住事件  end

    //保存成功！对当前标签添加标记  start
    function saveSeccessTab() {
        $('#addCaseNavTabs li.active').attr('data-save', 'yes');
    }

    //保存成功！对当前标签添加标记  end


    // 页面加载 获取保存过的页面  start
    function getSavePage(recordId) {
        var result = {record_id: recordId, items: 'physical,auxiliary,diagnose,dispose,follow'};
        $.get('/manage/record/items', result, function (data) {
            if (data.code == '10000') {
                $.each(data.data, function (i, v) {
                    if (v) {
                        $('#addCaseNavTabs li[data-href="' + i + '"]').attr('data-save', 'yes');
                    }
                });
                $('#addCaseNavTabs').attr('data-know', 'yes');
            }
        });
    }// 页面加载 获取保存过的页面  end
    //页面刷新  根据浏览器sessionStorage存储的病历id获取患者基本信息  start
    var patient_id = sessionStorage.getItem('patient_id');//保存患者id值
    var record_id = sessionStorage.getItem('record_id');//保存病历id值

    //医院改变获取医生  start
    $('#hospitalId').change(function () {
        hospitalChange($(this).val());
    });

    function hospitalChange(hospital_id, doctor_id) {
        if (!hospital_id) {
            return;
        }
        if (hospital_id !== "") {
            $.get('/manage/hospital/doctors', {hospital_id: hospital_id}, function (data) {
                if (data.code === 10000) {
                    var str = '';
                    $.each(data.data, function (i, v) {
                        if (doctor_id && doctor_id == v.id) {
                            str += '<option value="' + v.id + '" selected>' + v.name + '</option>';
                        } else {
                            str += '<option value="' + v.id + '">' + v.name + '</option>';
                        }
                    });
                    $('#doctorId').html(str);
                } else if (data.code === 40100) {
                    aClick();
                } else {
                    alertModel('', data.message);
                }
            });

        }
    }

    //医院改变获取医生  end
    // 获取患者基本信息  start
    var getPatientBaseMessUrl = '/manage/record/edit';

    function getPatientBaseMess(record_id) {
        var d = 'record_id=' + record_id + '&include=hospital:need,patient:include(address),doctor';
        $.get(getPatientBaseMessUrl, d, function (data) {
            if (data.code === 10000) {
                var result = data.data.patient;
                if (result.hospital && result.hospital.value) {
                    if (result.hospital.value.length > 8) {
                        result.hospital.value = result.hospital.value.slice(0, 8) + '...';
                    }
                }
                if (result.medical_number) {
                    if (result.medical_number.length > 15) {
                        result.medical_number = result.medical_number.slice(0, 15) + '...';
                    }
                }

                //存储手机号  用于点处理保存跳转列表页  搜索
                sessionStorage.setItem('patientPhone', result.phone);
                new Yox({
                    el: '#baseMessageForm',
                    template: '#baseMessageComp',
                    data: {
                        baseMess: result
                    }
                });
                //填写复诊信息
                $('#visit_message #clinicAt').val(data.data.clinic_at);
                $('#visit_message #hospitalId').val(data.data.hospital_id);
                if (!($('li.nav-header strong.font-bold').attr('data-doctor'))) {
                    hospitalChange(data.data.hospital_id, data.data.doctor_id);
                } else {
                    $('#visit_message #doctorId').val(data.data.doctor_id);
                }

                $(".hospitalIdF").val(data.data.hospital_id);
            } else if (data.code === 40100) {
                aClick();
            } else {
                $.alert({
                    title: '温馨提示',
                    body: data.message,
                    transition: true,
                    okHidden: function () {
                    }
                });
            }
        });
    }

    // 获取患者基本信息  end
    if (record_id) {
        getSavePage(record_id);
        $('input#record_id').val(record_id);//将病历id存入页面基本信息下隐藏输入框中
        getPatientBaseMess(record_id);// 页面加载时获取患者基本信息和复诊信息
        var timer = setInterval(function () {
            if ($('#addCaseNavTabs').attr('data-know')) {
                clearInterval(timer);
                if (($('#addCaseNavTabs li.active').attr('data-js')) == 'caseVisit') {
                    var tabPage = $('#addCaseNavTabs li.active').attr('data-href');

                    if ($('#addCaseNavTabs li.active').attr('data-save') == 'yes') {
                        beforeGetData(tabPage);
                    } else {
                        var result = {record_id: record_id, include: 'previousSub,previousMedication'};

                        previousSubData(result);
                    }
                }
            }
        }, 10);
    } else if (patient_id) {
        $.get('/manage/patient/edit', {patient_id: patient_id, include: 'address'}, function (data) {
            if (data.code === 10000) {
                var result = data.data;
                if (result.hospital && result.hospital.value) {
                    if (result.hospital.value.length > 8) {
                        result.hospital.value = result.hospital.value.slice(0, 8) + '...';
                    }
                }
                if (result.medical_number) {
                    if (result.medical_number.length > 15) {
                        result.medical_number = result.medical_number.slice(0, 15) + '...';
                    }
                }

                //存储手机号  用于点处理保存跳转列表页  搜索
                sessionStorage.setItem('patientPhone', result.phone);
                new Yox({
                    el: '#baseMessageForm',
                    template: '#baseMessageComp',
                    data: {
                        baseMess: result
                    }
                });
                if (result.cardnumber) {
                    $("#cardSearch .cardSearchBox").find('input').val(result.cardnumber).attr("readonly", 'readonly');
                    $('#cardNoSearch').click();
                }

                $(".hospitalIdF").val(data.data.hospital.key);


            } else if (data.code === 40100) {
                aClick();
            } else {
                $.alert({
                    title: '温馨提示',
                    body: data.message,
                    transition: true,
                    okHidden: function () {
                    }
                });
            }
        });
        var result = {patient_id: patient_id, include: 'previousSub,previousMedication'};
        previousSubData(result);
    }
    //页面刷新时候  根据浏览器sessionStorage存储的病历id获取患者基本信息  end

    //遍历上次就诊情况数据并拼接字符串放入页面  start
    function previousSubGroup(data) {
        data = data.data;
        var str = '';
        for (var i = 0; i < data.length; i++) {
            // for (var i = 0; i < data.data.length; i++) {
            str += '<div class="hpiSub"><div class="row margin-top-15 szView"><div class="col-xs-12"><div class="szViewDiv" data-name="started_at">' +
                '<span class="input-title">起病日期</span><input type="text" class="form-control input-value" value="' + data[i].started_at + '" disabled></div>' +
                '<div class="szViewDiv" data-name="inducement"><span class="input-title">诱因</span><input type="text" class="form-control input-value" value="' + data[i].inducement.value + '" disabled>' +
                '</div><div class="szViewDiv" data-name="clinic_site"><span class="input-title">就诊地点</span><input type="text" class="form-control input-value" value="' + data[i].clinic_site + '" disabled></div></div><div class="col-xs-12">' +
                '<span class="input-title">起病症状</span><ul class="sz-sui-tag">';
            if (data[i].symptoms) {
                for (var j = 0; j < data[i].symptoms.length; j++) {
                    str += '<li class="tag-selected">' + data[i].symptoms[j] + '</li>'
                }
            }
            var One = Two = Three = Four = Five = Six = Seven = Eight = Nine = "";
            if (data[i].before_treatment) {
                if (data[i].before_treatment.fbg) {
                    One = data[i].before_treatment.fbg.low;
                    Two = data[i].before_treatment.fbg.high;
                }
                ;
                if (data[i].before_treatment['2hpbg']) {
                    Three = data[i].before_treatment['2hpbg'].low;
                    Four = data[i].before_treatment['2hpbg'].high;
                }
                Five = data[i].before_treatment.hba1c;

            }
            ;
            if (data[i].after_treatment) {
                if (data[i].after_treatment.fbg) {
                    Six = data[i].after_treatment.fbg.low;
                    Seven = data[i].after_treatment.fbg.high;
                }
                if (data[i].after_treatment['2hpbg']) {
                    Eight = data[i].after_treatment['2hpbg'].low;
                    Nine = data[i].after_treatment['2hpbg'].high;
                }
            }


            str += '</ul></div></div><div class="row margin-top-15 xbs-input-two"><div class="col-xs-12 bloodInput" data-name="before_treatment"><span class="xbs-input-title">平时血糖值</span><div class="xbs-input-box"><span>空腹血糖</span><div class="input-content" data-name="fbg"> ' +
                '<input type="number" data-name="low" name="before_n_glood_low" class="form-control" disabled value="' + One + '"> <span>-</span>' +
                '<input type="number" data-name="high" name="before_n_glood_high" class="form-control" disabled value="' + Two + '"><span>mmol/L</span></div></div><div class="xbs-input-box"><span>餐后2h血糖</span><div class="input-content" data-name="2hpbg">' +
                '<input type="number" data-name="low" name="before_d_glood_low" class="form-control" disabled value="' + Three + '"> <span>-</span>' +
                '<input type="number" data-name="high" name="before_d_glood_high" class="form-control" disabled value="' + Four + '"><span>mmol/L</span></div></div><div class="xbs-input-box">' +
                '<span>HbA1c</span><div class="input-content" data-name="hba1c"><input type="number" data-name="hba1c" name="hba1c" class="form-control" disabled value="' + Five + '"><span>mmol/L</span></div></div></div><div class="col-xs-12 margin-top-15 bloodInput" data-name="after_treatment" disabled><span class="xbs-input-title">治疗后血糖值</span><div class="xbs-input-box"><span>空腹血糖</span><div class="input-content" data-name="fbg">' +
                '<input type="number" data-name="low" name="after_n_glood_low" class="form-control" disabled value="' + Six + '"> <span>-</span>' +
                '<input type="number" data-name="high" name="after_n_glood_high" class="form-control" disabled value="' + Seven + '"><span>mmol/L</span></div></div><div class="xbs-input-box"><span>餐后2h血糖</span><div class="input-content" data-name="2hpbg">' +
                '<input type="number" data-name="low" name="after_d_glood_low" class="form-control" disabled value="' + Eight + '"> <span>-</span>' +
                '<input type="number" data-name="high" name="after_d_glood_high" class="form-control" disabled value="' + Nine + '"> <span>mmol/L</span></div></div></div></div>';
            if (data[i].diagnose.length) {
                str += diagnoseStr(data[i].diagnose);
            }
            if (data[i].medication) {
                if (data[i].medication.length) {
                    str += medicationStr(data[i].medication);
                }
            }

            if (data[i].cn_medication && data[i].cn_medication.length) {
                str += cn_medicationStr(data[i].cn_medication);
            }
            str += '</div><input type="hidden" class="szGroupId" value="' + data[i].id + '">';
        }
        $('#previousHpi').html(str);

    }

    //西药遍历拼接
    function medicationStr(medication) {
        var str = '';
        str += '<div class="row margin-top-25"><div class="col-xs-12 table-title table-title-medication">西药</div></div>' +
            '<div class="row margin-top-5"><div class="col-xs-12 xbsAddMedication"><table class="table-bordered table-striped table-hover text-center medicationList-table"><thead><tr><th>开始时间</th><th>结束时间</th><th>名称</th><th>剂量</th><th>单位</th><th>用法</th><th>频次</th><th>其他备注</th><th class="opa">操作</th></tr></thead><tbody>';
        for (var a = 0; a < medication.length; a++) {
            str += '<tr class="medication1"><td>' + checkUndefined(medication[a].start_time) + '</td>' +
                '<td>' + checkUndefined(medication[a].end_time) + '</td>' +
                '<td>' + checkUndefined(medication[a].name) + '</td>';
            if (medication[a].dosage.type == '分次剂量') {
                str += '<td><span>早上' + checkUndefined(medication[a].dosage.values.morning) + '</span><span> 中午' + checkUndefined(medication[a].dosage.values.atnoon) + '</span><span> 晚上' + checkUndefined(medication[a].dosage.values.evening) + '</span><span> 睡前' + checkUndefined(medication[a].dosage.values.before_sleep) + '</span></td>';
            } else if (medication[a].dosage.type == '每次剂量') {
                str += '<td>' + checkUndefined(medication[a].dosage.value) + '</td>';
            }
            str += '<td>' + checkUndefined(medication[a].dosage.unit) + '</td>' +
                '<td>' + checkUndefined(medication[a].usage) + '</td>' +
                '<td>' + checkUndefined(medication[a].frequency) + '</td>' +
                '<td>' + checkUndefined(medication[a].remark) + '</td>' +
                '<td class="deleteTd"><button type="button" class="btn btn-outline btn-primary margin-right-5 editMedicationBtn disabled" disabled>编辑</button>' +
                '<button type="button" class="btn btn-outline btn-danger addMedicationDelete disabled" disabled>删除</button></td></tr>'
        }
        str += '</tbody></table></div></div> ';
        return str;
    }

    //中药遍历拼接
    function cn_medicationStr(cn_medication) {
        var str = '';
        str += '<div class="hpiTcm chineseMedicineBox"><div class="row margin-top-25"><div class="col-xs-12 table-title table-title-tcm">汤药</div></div>' +
            '<div class="row margin-top-5 margin-bottom-15"><div class="col-xs-12 xbsAddTcm"><table class="table-bordered table-striped table-hover text-center tcm-table"><thead><tr><th>名称剂量</th><th>煎服方法</th><th class="opa">操作</th></tr></thead><tbody>';
        for (var b = 0; b < cn_medication.length; b++) {
            if (cn_medication[b].type != 3) {
                str += '<tr class="tcm1"><td>';
                if (cn_medication[b].drugs) {
                    for (var i = 0; i < cn_medication[b].drugs.length; i++) {
                        str += '<span>' + cn_medication[b].drugs[i].name + ' ' + cn_medication[b].drugs[i].weight + 'g </span>';
                    }
                }
                str += '</td><td>煎法：' + cn_medication[b].usage + ' 频次：' + cn_medication[b].dosage + '，' + cn_medication[b].frequency + ' 总数：' + cn_medication[b].dose + '付</td>' +
                    '<td class="deleteTd"><button type="button" class="btn btn-outline btn-primary margin-right-5 addTcmEdit disabled" disabled>编辑</button>' +
                    '<button type="button" class="btn btn-outline btn-danger addTcmDelete disabled" disabled>删除</button></td></tr>';
            } else {
                var title = cn_medication[b].name;
                var times = cn_medication[b].times_per_day;
                var numMe = cn_medication[b].quantity_per_times;
                var boxNum = cn_medication[b].total;
                var stime = cn_medication[b].start_time;
                var etime = cn_medication[b].end_time;
                var unit = cn_medication[b].quantity_unit;
                str += '<tr class="tcm' + (b + 1) + '" data-type="3" ><td><span>' + title +
                    '<input type="hidden" value="' + title + '" class="tableSelectTcm"></span>';

                var sDataText, eDataText;
                sDataText = (stime !== "") ? ( "， 开始时间：") : "";
                eDataText = (etime !== "") ? (" 结束时间：") : "";
                str += '</td><td>每日：' + times + ' 次， 每次：' + numMe + unit + '，总数：' + boxNum + '盒' + sDataText + stime + eDataText + etime +
                    '<input type="hidden" class="stime" value="' + stime + '">' +
                    '<input type="hidden" class="etime" value="' + etime + '">' +
                    '<input type="hidden" class="times" value="' + times + '">' +
                    '<input type="hidden" class="numMe" value="' + numMe + '"><' +
                    'input type="hidden" class="unit" value="' + unit + '"><' +
                    'input type="hidden" class="boxNum" value="' + boxNum + '"></td>';
                str += '<td class="deleteTd">' +
                    '<button type="button" class="btn btn-outline btn-primary margin-right-5 addTcmEdit"  data-toggle="modal" data-target="#addTcm" data-id="clAddTcm" data-edit="tcm' + (b + 1) + '">编辑</button>' +
                    '<button type="button" class="btn btn-outline btn-danger addTcmDelete">删除</button></td>';
            }

        }
        str += '</tbody></table></div></div></div>';
        return str;
    }

    //诊断遍历拼接
    function diagnoseStr(diagnose) {
        var str = '';
        str += '<div class="row margin-top-25"><div class="col-xs-12 table-title table-title-diagnosis">诊断</div></div>' +
            '<div class="row margin-top-5"><div class="col-xs-12 xbsAddDiagnosis"><table class="table-bordered table-striped table-hover text-center diagnosis-table"><thead><tr><th>病名</th><th>ICD编码</th><th class="opa">操作</th></tr></thead><tbody>';
        for (var c = 0; c < diagnose.length; c++) {
            str += '<tr><td>' + diagnose[c].name + '</td><td>' + diagnose[c].icd + '</td><td class="deleteTd">' +
                '<button type="button" class="btn btn-outline btn-danger deleteDiagnosisBtn disabled" disabled>删除</button></td></tr>'
        }
        str += '</tbody></table></div></div> ';
        return str;
    }

    //遍历上次就诊情况数据并拼接字符串放入页面  end

    //请求随诊 上次就诊情况 数据 start
    function previousSubData(result) {
        var url = '/manage/follow/previous';
        $.get(url, result, function (data) {
            if (data.code == '10000') {
                if (data.data.previousSub.data.length > 0) {
                    previousSubGroup(data.data.previousSub);
                    // previousSubGroup(data.data.previousSub.data);
                }
                //放置  目前用药情况数据  S
                if (data.data.previousMedication.medication) {
                    if (data.data.previousMedication.medication.length) {
                        var medicationData = data.data.previousMedication.medication;
                        var medication_str = medicationStr(medicationData);
                        $('#szMedicationFixed').html(medication_str);
                    }
                }
                if (data.data.previousMedication.cn_medication) {
                    if (data.data.previousMedication.cn_medication.length) {
                        var tcmData = data.data.previousMedication.cn_medication;
                        var tcmStr = cn_medicationStr(tcmData);
                        $('#szTcmFixed').html(tcmStr);
                    }
                }
                if (data.data.previousMedication.medication && data.data.previousMedication.cn_medication) {
                    if (!data.data.previousMedication.medication.length && !data.data.previousMedication.cn_medication.length) {
                        $('#szMedTacBox').addClass('display-none');
                    }
                } else {
                    if (data.data.previousMedication.medication && !data.data.previousMedication.medication.length) {
                        $('#szMedTacBox').addClass('display-none');
                    }
                }
                //放置  目前用药情况数据  E


            } else if (data.code == '40001') {
                $('#szMedTacBox').addClass('display-none');
            } else {
                alertModel('', data.message);
            }
        })
    }

    //请求随诊 上次就诊情况 数据 end

    //页面刷新 或者 标签页点击  获取当前信息  start
    function beforeGetData(tabPage) {
        var url = '/manage/' + tabPage + '/edit';
        var result = {record_id: record_id};
        if (tabPage == 'follow') {
            result = {record_id: record_id, include: 'hpiSub,previousSub,previousMedication'};
        }
        GetData(url, result, tabPage);
    }//页面刷新 或者 标签页点击  获取当前信息  end
    //获取数据 请求方法 封装函数  start
    function GetData(url, result, success) {
        $.get(url, result, function (data) {
            if (data.code == '10000') {
                $('#addCaseNavTabs li[data-href="' + success + '"]').attr('data-load', 'yes');
                if (success === 'follow') {
                    follow(data.data);
                }
            } else {
                alertModel('', data.message);
            }
        })
    }//获取数据 请求方法 封装函数  end
    //随诊  处理数据方法  start
    function appendLi(data) {
        var html = "";
        $.each(data, function (k, v) {
            html += '<li class="tag-selected with-x" data-id="symptomName" data-name="' + v + '"><input type="hidden" value="' + v + '" name="symptom[]">' + v + '<i>×</i></li>';
        });
        return html;
    }

    // function follow(data) {
    //     $('#suizhen input.szId').val(data.id);
    //     //放置  一般情况数据
    //     if (data.diet) {
    //         $('#suizhen .xbs-table div[data-name="staple"]').find('input').val(data.diet.staple);
    //         var tdFirst = $('#suizhen .xbs-table td[data-name="diet"] div.xgb-foods-type');
    //         for (var i = 0; i < tdFirst.length; i++) {
    //             var tdKey = $(tdFirst[i]).attr('data-name');
    //             if (data.diet[tdKey] != 2) {
    //                 $(tdFirst[i]).find('input[value="' + data.diet[tdKey] + '"]').attr('checked', 'checked');
    //                 $(tdFirst[i]).find('input[value="2"]').removeAttr('checked');
    //             }
    //         }
    //     }
    //     if (data.normal) {
    //         var tdNormal = $('#suizhen .xbs-table td[data-name="normal"] div.xgb-foods-type');
    //         for (var j = 0; j < tdNormal.length; j++) {
    //             var tdNormalKey = $(tdNormal[j]).attr('data-name');
    //             var type = $(tdNormal[j]).attr('data-type');
    //             if (type == 'obj') {
    //                 $(tdNormal[j]).find('.form-control').val(data.normal[tdNormalKey][$(tdNormal[j]).find('.form-control').attr('data-name')]);
    //             } else {
    //                 if (data.normal[tdNormalKey] != 1) {
    //                     $(tdNormal[j]).find('input[value="' + data.normal[tdNormalKey] + '"]').attr('checked', 'checked');
    //                     $(tdNormal[j]).find('input[value="1"]').removeAttr('checked');
    //                 }
    //             }
    //         }
    //     }
    //
    //     $('#suizhen .xbs-table td[data-name="sport"] .form-control').val(data.sport);
    //     //放置自我血糖检测情况数据  S
    //     var bloodGlucoseDiv = $('#suizhen div.blood_glucose div[data-name]');
    //     for (var m = 0; m < bloodGlucoseDiv.length; m++) {
    //         var bloodGlucoseDivKey = $(bloodGlucoseDiv[m]).attr('data-name');
    //         var bloodGlucoseDivInput = $(bloodGlucoseDiv[m]).find('input');
    //         for (var w = 0; w < bloodGlucoseDivInput.length; w++) {
    //             var inputKey = $(bloodGlucoseDivInput[w]).attr('data-name');
    //             if (data.blood_glucose && data.blood_glucose[bloodGlucoseDivKey]) {
    //                 $(bloodGlucoseDivInput[w]).val(data.blood_glucose[bloodGlucoseDivKey][inputKey]);
    //             }
    //         }
    //     }
    //     //放置自我血糖检测情况数据  E
    //     //放置 上次就诊至本次就诊间隔情况评价 数据  S
    //     var intervalEvaluationDiv = $('#suizhen div.interval_evaluation');
    //     if (data.interval_evaluation) {
    //         intervalEvaluationDiv.find('input.remark').val(data.interval_evaluation.remark);
    //     }
    //     if (data.interval_evaluation) {
    //         var blood_glucose = data.interval_evaluation.blood_glucose;
    //         if (blood_glucose != 1) {
    //             intervalEvaluationDiv.find('div.blood_glucose input[value="' + blood_glucose + '"]').attr('checked', 'checked');
    //             intervalEvaluationDiv.find('div.blood_glucose input[value="1"]').removeAttr('checked');
    //         }
    //         var hypoglycemia = data.interval_evaluation.hypoglycemia;
    //         if (hypoglycemia != 1) {
    //             intervalEvaluationDiv.find('div.hypoglycemia input[value="' + hypoglycemia + '"]').attr('checked', 'checked');
    //             intervalEvaluationDiv.find('div.hypoglycemia input[value="1"]').removeAttr('checked');
    //         }
    //         var weight_change = data.interval_evaluation.weight.change;
    //         intervalEvaluationDiv.find('select.zsWeightChangeSelect').val(weight_change);
    //         if (weight_change != 0) {
    //             intervalEvaluationDiv.find('select.zsWeightchangestatus').val(data.interval_evaluation.weight.effect);
    //             intervalEvaluationDiv.find('div.zsWeightChangeSize').css('display', 'block');
    //             if (data.interval_evaluation.weight.effect == 2) {
    //                 intervalEvaluationDiv.find('div.zsWeightChangeSize input').css('display', 'none');
    //                 intervalEvaluationDiv.find('div.zsWeightChangeSize span').css('display', 'none');
    //             } else {
    //                 intervalEvaluationDiv.find('div.zsWeightChangeSize input').val(data.interval_evaluation.weight.kg);
    //             }
    //         }
    //     }
    //
    //
    //     //放置 上次就诊至本次就诊间隔情况评价 数据  E
    //     //放置 上次就诊至本次就诊间隔症状 数据  S
    //     if (data.interval_symptom) {
    //         $('#suizhen div.interval_symptom input.remark').val(data.interval_symptom.remark);
    //         var symptomsArr = data.interval_symptom.symptoms;
    //         if (symptomsArr.length) {
    //             var symptomsInput = $('#szSymptom ul.interval_symptom');
    //             var str = '';
    //             for (var z = 0; z < symptomsArr.length; z++) {
    //                 str += '<li class="tag-selected with-x" data-id="symptomName" data-name="' + symptomsArr[z] + '"><input type="hidden" value="' + symptomsArr[z] + '" name="symptom[]">' + symptomsArr[z] + '<i>×</i></li>'
    //             }
    //             symptomsInput.html(str);
    //         }
    //     }
    //
    //     //放置 上次就诊至本次就诊间隔症状 数据  E
    //     //放置随诊组  数据  S
    //
    //     var xbsGroupData = data.hpiSub.data;
    //     szPlace(xbsGroupData, 'suizhen', 'addSzBox', 'szGroup');
    //     if (xbsGroupData.length >= 5) {
    //         $('#addSzGroup').addClass('disabled');
    //         $('#addSzGroup').attr('disabled', 'disabled');
    //     }
    //     //放置随诊组  数据  E
    //     //放置  目前用药情况数据  S
    //     if (data.previousMedication) {
    //         if (data.previousMedication.medication) {
    //             if (data.previousMedication.medication.length) {
    //                 var medicationData = data.previousMedication.medication;
    //                 var medication_str = medicationStr(medicationData);
    //                 $('#szMedicationFixed').html(medication_str);
    //             }
    //         }
    //
    //         if (data.previousMedication.cn_medication) {
    //             if (data.previousMedication.cn_medication.length) {
    //                 var tcmData = data.previousMedication.cn_medication;
    //                 var tcmStr = cn_medicationStr(tcmData);
    //                 $('#szTcmFixed').html(tcmStr);
    //             }
    //         }
    //         if (data.previousMedication.cn_medication) {
    //             if (data.previousMedication.medication) {
    //                 if (!data.previousMedication.medication.length && !data.previousMedication.cn_medication.length) {
    //                     $('#szMedTacBox').addClass('display-none');
    //                 }
    //             }
    //
    //         }
    //         else {
    //             if (data.previousMedication.medication) {
    //                 if (!data.previousMedication.medication.length) {
    //                     $('#szMedTacBox').addClass('display-none');
    //                 }
    //             }
    //
    //         }
    //     }
    //
    //     //放置  目前用药情况数据  E
    //     //放置  原有随诊数据  S
    //     //szPlace(data.previousSub,'suizhen','szFixedGroup','szFixedGroup');
    //     // if (data.previousSub.length > 0) {
    //     if (data.previousSub.data.length > 0) {
    //         previousSubGroup(data.previousSub);
    //     }
    //     //放置  原有随诊数据  E
    //     $('#suizhen #szRemark').val(data.remark);
    //
    //
    //     //甲状腺放置数据⬇️
    //     if (data.thyroid) {
    //         if (data.thyroid.started_at) {
    //             $(".thyroidStarted_at").val(data.thyroid.started_at)
    //         }
    //         if (data.thyroid.symptoms_remark) {
    //             $(".thyroid_symptoms_remark").val(data.thyroid.symptoms_remark)
    //         }
    //         if (data.thyroid.examination_remark) {
    //             $(".examination_remark").val(data.thyroid.examination_remark)
    //         }
    //         if (data.thyroid.hyperthyroidism_remark) {
    //             $(".hyperthyroidism_remark").val(data.thyroid.hyperthyroidism_remark)
    //         }
    //         if (data.thyroid.inducement) {
    //             $(".thyroidInducement option[value=" + data.thyroid.inducement + "]").attr("selected", "selected")
    //         }
    //         if (data.thyroid.symptoms) {
    //             $("ul.thyroid").html(appendLi(data.thyroid.symptoms))
    //         }
    //         ;
    //         if (data.thyroid.examination) {
    //             $("ul.thyroid1").html(appendLi(data.thyroid.examination))
    //         }
    //         ;
    //         if (data.thyroid.hyperthyroidism) {
    //             $("ul.thyroid2").html(appendLi(data.thyroid.hyperthyroidism))
    //         }
    //         ;
    //     }
    //
    //     //高血压数据放置⬇️
    //     if (data.adrenal_gland) {
    //         if (data.adrenal_gland.started_at) {
    //             $("#highBlood").find(".started_at").val(data.adrenal_gland.started_at)
    //         }
    //         if (data.adrenal_gland.symptoms_remark) {
    //             $(".symptoms_remark").val(data.adrenal_gland.symptoms_remark)
    //         }
    //         if (data.adrenal_gland.accompanied_symptom_remark) {
    //             $(".accompanied_symptom_remark").val(data.adrenal_gland.accompanied_symptom_remark)
    //         }
    //         if (data.adrenal_gland.hyperthyroidism) {
    //             $("ul.highBlood").html(appendLi(data.adrenal_gland.symptoms))
    //         }
    //         ;
    //         if (data.adrenal_gland.accompanied_symptom) {
    //             $("ul.highBlood1").html(appendLi(data.adrenal_gland.accompanied_symptom))
    //         }
    //         ;
    //         if (data.adrenal_gland.symptoms) {
    //             $("ul.highBlood").html(appendLi(data.adrenal_gland.symptoms))
    //         }
    //         ;
    //
    //     }
    //
    //     // //随诊组只显示一组；默认最后添加的一组
    //     // $("#szGroup1").hide();
    //     // $("#szGroup2").hide();
    //     // $("#szGroup3").hide();
    //
    // }//随诊  处理数据方法  end

    function follow(data) {
        $('#suizhen input.szId').val(data.id);
        //放置  一般情况数据
        if (data.diet) {
            $('#suizhen .xbs-table div[data-name="staple"]').find('input').val(data.diet.staple);
            var tdFirst = $('#suizhen .xbs-table td[data-name="diet"] div.xgb-foods-type');
            for (var i = 0; i < tdFirst.length; i++) {
                var tdKey = $(tdFirst[i]).attr('data-name');
                if (data.diet[tdKey] != 2) {
                    $(tdFirst[i]).find('input[value="' + data.diet[tdKey] + '"]').attr('checked', 'checked');
                    $(tdFirst[i]).find('input[value="2"]').removeAttr('checked');
                }
            }
            (data.diet.breakfast) && $(".breakfast").val(data.diet.breakfast);
            (data.diet.breakfastAdditional) && $(".breakfastAdditional").val(data.diet.breakfastAdditional);
            (data.diet.lunch) && $(".lunch").val(data.diet.lunch);
            (data.diet.lunchAdditional) && $(".lunchAdditional").val(data.diet.lunchAdditional);
            (data.diet.dinner) && $(".dinner").val(data.diet.dinner);
            (data.diet.dinnerAdditional) && $(".dinnerAdditional").val(data.diet.dinnerAdditional);

        }
        if (data.normal) {
            var tdNormal = $('#suizhen .xbs-table td[data-name="normal"] div.xgb-foods-type');
            for (var j = 0; j < tdNormal.length; j++) {
                var tdNormalKey = $(tdNormal[j]).attr('data-name');
                var type = $(tdNormal[j]).attr('data-type');
                if (type == 'obj') {
                    if (tdNormalKey == 'shit') {
                        (data.normal[tdNormalKey]['frequency']) && $('.frequency').val(data.normal[tdNormalKey]['frequency']);
                        (data.normal[tdNormalKey]['remark']) && $('.remark').val(data.normal[tdNormalKey]['remark']);
                        (data.normal[tdNormalKey]['value']) && $('.value[value="' + data.normal[tdNormalKey]['value'] + '"]').attr('checked', 'checked');
                        (data.normal[tdNormalKey]['customFrequency']) && $('.customFrequency').val(data.normal[tdNormalKey]['customFrequency']);


                    } else if (tdNormalKey == 'sweat') {
                        (data.normal[tdNormalKey]['situation']) && $('.sweatInput[value="' + data.normal[tdNormalKey]['situation'] + '"]').attr('checked', 'checked');
                        (data.normal[tdNormalKey]['remark']) && $('.sweatRemark').val(data.normal[tdNormalKey]['remark']);
                    } else if (tdNormalKey != 'DysuriaYN' && tdNormalKey != 'sweat') {
                        $(tdNormal[j]).find('.form-control').val(data.normal[tdNormalKey][$(tdNormal[j]).find('.form-control').attr('data-name')]);
                        (data.normal[tdNormalKey]['difficulty']) && $('.peeDif[value="' + data.normal[tdNormalKey]['difficulty'] + '"]').attr('checked', 'checked');


                    }
                } else {
                    if (data.normal[tdNormalKey] != 1) {
                        $(tdNormal[j]).find('input[value="' + data.normal[tdNormalKey] + '"]').attr('checked', 'checked');
                        $(tdNormal[j]).find('input[value="1"]').removeAttr('checked');
                    }
                }
            }
        }

        $('#suizhen .xbs-table td[data-name="sport"] .sport').val(data.sport);
        $('#suizhen .xbs-table td[data-name="sport"] .sport_strength').val(data.sport_strength);
        $('#suizhen .xbs-table td[data-name="sport"] .sport_time').val(data.sport_time);
        //放置自我血糖检测情况数据  S
        var bloodGlucoseDiv = $('#suizhen div.blood_glucose div[data-name]');
        for (var m = 0; m < bloodGlucoseDiv.length; m++) {
            var bloodGlucoseDivKey = $(bloodGlucoseDiv[m]).attr('data-name');
            var bloodGlucoseDivInput = $(bloodGlucoseDiv[m]).find('input');
            for (var w = 0; w < bloodGlucoseDivInput.length; w++) {
                var inputKey = $(bloodGlucoseDivInput[w]).attr('data-name');
                if (data.blood_glucose && data.blood_glucose[bloodGlucoseDivKey]) {
                    $(bloodGlucoseDivInput[w]).val(data.blood_glucose[bloodGlucoseDivKey][inputKey]);
                }
            }
        }
        //放置自我血糖检测情况数据  E
        //放置 上次就诊至本次就诊间隔情况评价 数据  S
        var intervalEvaluationDiv = $('#suizhen div.interval_evaluation');
        if (data.interval_evaluation) {
            intervalEvaluationDiv.find('input.remark').val(data.interval_evaluation.remark);
        }
        if (data.interval_evaluation) {
            var blood_glucose = data.interval_evaluation.blood_glucose;
            if (blood_glucose != 1) {
                intervalEvaluationDiv.find('div.blood_glucose input[value="' + blood_glucose + '"]').attr('checked', 'checked');
                intervalEvaluationDiv.find('div.blood_glucose input[value="1"]').removeAttr('checked');
            }
            var hypoglycemia = data.interval_evaluation.hypoglycemia;
            if (hypoglycemia != 1) {
                intervalEvaluationDiv.find('div.hypoglycemia input[value="' + hypoglycemia + '"]').attr('checked', 'checked');
                intervalEvaluationDiv.find('div.hypoglycemia input[value="1"]').removeAttr('checked');
            }
            var weight_change = data.interval_evaluation.weight.change;
            intervalEvaluationDiv.find('select.zsWeightChangeSelect').val(weight_change);
            if (weight_change != 0) {
                intervalEvaluationDiv.find('select.zsWeightchangestatus').val(data.interval_evaluation.weight.effect);
                intervalEvaluationDiv.find('div.zsWeightChangeSize').css('display', 'block');
                if (data.interval_evaluation.weight.effect == 2) {
                    intervalEvaluationDiv.find('div.zsWeightChangeSize input').css('display', 'none');
                    intervalEvaluationDiv.find('div.zsWeightChangeSize span').css('display', 'none');
                } else {
                    intervalEvaluationDiv.find('div.zsWeightChangeSize input').val(data.interval_evaluation.weight.kg);
                }
            }
        }


        //放置 上次就诊至本次就诊间隔情况评价 数据  E
        //放置 上次就诊至本次就诊间隔症状 数据  S
        if (data.interval_symptom) {
            $('#suizhen div.interval_symptom input.remark').val(data.interval_symptom.remark);
            var symptomsArr = data.interval_symptom.symptoms;
            if (symptomsArr.length) {
                var symptomsInput = $('#szSymptom ul.interval_symptom');
                var str = '';
                for (var z = 0; z < symptomsArr.length; z++) {
                    str += '<li class="tag-selected with-x" data-id="symptomName" data-name="' + symptomsArr[z] + '"><input type="hidden" value="' + symptomsArr[z] + '" name="symptom[]">' + symptomsArr[z] + '<i>×</i></li>'
                }
                symptomsInput.html(str);
            }
        }

        //放置 上次就诊至本次就诊间隔症状 数据  E
        //放置随诊组  数据  S

        var xbsGroupData = data.hpiSub.data;
        szPlace(xbsGroupData, 'suizhen', 'addSzBox', 'szGroup');
        if (xbsGroupData.length >= 5) {
            $('#addSzGroup').addClass('disabled');
            $('#addSzGroup').attr('disabled', 'disabled');
        }
        //放置随诊组  数据  E
        //放置  目前用药情况数据  S
        if (data.previousMedication) {
            if (data.previousMedication.medication) {
                if (data.previousMedication.medication.length) {
                    var medicationData = data.previousMedication.medication;
                    var medication_str = medicationStr(medicationData);
                    $('#szMedicationFixed').html(medication_str);
                }
            }

            if (data.previousMedication.cn_medication) {
                if (data.previousMedication.cn_medication.length) {
                    var tcmData = data.previousMedication.cn_medication;
                    var tcmStr = cn_medicationStr(tcmData);
                    $('#szTcmFixed').html(tcmStr);
                }
            }
            if (data.previousMedication.cn_medication) {
                if (data.previousMedication.medication) {
                    if (!data.previousMedication.medication.length && !data.previousMedication.cn_medication.length) {
                        $('#szMedTacBox').addClass('display-none');
                    }
                }

            }
            else {
                if (data.previousMedication.medication) {
                    if (!data.previousMedication.medication.length) {
                        $('#szMedTacBox').addClass('display-none');
                    }
                }

            }
        }

        //放置  目前用药情况数据  E
        //放置  原有随诊数据  S
        //szPlace(data.previousSub,'suizhen','szFixedGroup','szFixedGroup');
        // if (data.previousSub.length > 0) {
        if (data.previousSub.data.length > 0) {
            previousSubGroup(data.previousSub);
        }
        //放置  原有随诊数据  E
        $('#suizhen #szRemark').val(data.remark);


        //甲状腺放置数据⬇️
        if (data.thyroid) {
            if (data.thyroid.started_at) {
                $(".thyroidStarted_at").val(data.thyroid.started_at)
            }
            if (data.thyroid.symptoms_remark) {
                $(".thyroid_symptoms_remark").val(data.thyroid.symptoms_remark)
            }
            if (data.thyroid.examination_remark) {
                $(".examination_remark").val(data.thyroid.examination_remark)
            }
            if (data.thyroid.hyperthyroidism_remark) {
                $(".hyperthyroidism_remark").val(data.thyroid.hyperthyroidism_remark)
            }
            if (data.thyroid.inducement) {
                $(".thyroidInducement option[value=" + data.thyroid.inducement + "]").attr("selected", "selected")
            }
            if (data.thyroid.symptoms) {
                $("ul.thyroid").html(appendLi(data.thyroid.symptoms))
            }
            ;
            if (data.thyroid.examination) {
                $("ul.thyroid1").html(appendLi(data.thyroid.examination))
            }
            ;
            if (data.thyroid.hyperthyroidism) {
                $("ul.thyroid2").html(appendLi(data.thyroid.hyperthyroidism))
            }
            ;
        }

        //高血压数据放置⬇️
        if (data.adrenal_gland) {
            if (data.adrenal_gland.started_at) {
                $("#highBlood").find(".started_at").val(data.adrenal_gland.started_at)
            }
            if (data.adrenal_gland.symptoms_remark) {
                $(".symptoms_remark").val(data.adrenal_gland.symptoms_remark)
            }
            if (data.adrenal_gland.accompanied_symptom_remark) {
                $(".accompanied_symptom_remark").val(data.adrenal_gland.accompanied_symptom_remark)
            }
            if (data.adrenal_gland.hyperthyroidism) {
                $("ul.highBlood").html(appendLi(data.adrenal_gland.symptoms))
            }
            ;
            if (data.adrenal_gland.accompanied_symptom) {
                $("ul.highBlood1").html(appendLi(data.adrenal_gland.accompanied_symptom))
            }
            ;
            if (data.adrenal_gland.symptoms) {
                $("ul.highBlood").html(appendLi(data.adrenal_gland.symptoms))
            }
            ;

        }

        // //随诊组只显示一组；默认最后添加的一组
        // $("#szGroup1").hide();
        // $("#szGroup2").hide();
        // $("#szGroup3").hide();

    }//随诊  处理数据方法  end


    //随诊  放置函数start
    function szPlace(xbsGroupData, parentId, GroupBoxId, szGroupId) {

        for (var q = 0; q < xbsGroupData.length; q++) {

            var xbsGroupDiv = $('#' + parentId + ' #' + GroupBoxId + '>div#' + szGroupId + q);
            xbsGroupDiv.find('input.szGroupId').val(xbsGroupData[q].id);
            xbsGroupDiv.find('div.szGroupSaveBox').removeClass('display-none');
            if (xbsGroupDiv.css('display') != 'block') {
                xbsGroupDiv.css('display', 'block');
            }
            //起病日期到症状
            xbsGroupDiv.find('div[data-name="started_at"] .form-control').val(xbsGroupData[q].started_at);
            xbsGroupDiv.find('div[data-name="inducement"] .form-control').val(xbsGroupData[q].inducement.key);
            xbsGroupDiv.find('div[data-name="clinic_site"] .form-control').val(xbsGroupData[q].clinic_site);
            var sympotmStr = '';
            if (GroupBoxId == 'addSzBox') {
                for (var m = 0; m < xbsGroupData[q].symptoms.length; m++) {
                    sympotmStr += '<li class="tag-selected with-x" data-id="symptomName" data-name="' + xbsGroupData[q].symptoms[m] + '"><input type="hidden" value="' + xbsGroupData[q].symptoms[m] + '" name="symptom[]">' + xbsGroupData[q].symptoms[m] + '<i>×</i></li>';
                }
                xbsGroupDiv.find('ul.sui-tag').html(sympotmStr);
            }
            else if (GroupBoxId == 'szFixedGroup') {
                for (var v = 0; v < xbsGroupData[q].symptoms.length; v++) {
                    sympotmStr += '<li class="tag-selected">' + xbsGroupData[q].symptoms[v] + '</li>';
                }
                xbsGroupDiv.find('ul.sz-sui-tag').html(sympotmStr);
            }
            //放置  血糖数据
            var bloodInput = xbsGroupDiv.find('div.bloodInput');
            for (var s = 0; s < bloodInput.length; s++) {
                var bloodKey = $(bloodInput[s]).attr('data-name');
                var bloodInputBox = $(bloodInput[s]).find('div[data-name]');
                for (var p = 0; p < bloodInputBox.length; p++) {
                    var bloodInputBoxKey = $(bloodInputBox[p]).attr('data-name');
                    if (bloodInputBoxKey == 'hba1c') {
                        $(bloodInputBox[p]).find('input').val(xbsGroupData[q][bloodKey] && xbsGroupData[q][bloodKey].hba1c)
                    } else {
                        $(bloodInputBox[p]).find('input[data-name="low"]').val(xbsGroupData[q][bloodKey] && xbsGroupData[q][bloodKey][bloodInputBoxKey].low);
                        $(bloodInputBox[p]).find('input[data-name="high"]').val(xbsGroupData[q][bloodKey] && xbsGroupData[q][bloodKey][bloodInputBoxKey].high);
                    }
                }
            }
            //放置添加诊断表格数据  S
            if (xbsGroupData[q].diagnose.length) {
                var zdStr = '<table class="table-bordered table-striped table-hover text-center diagnosis-table"><thead><tr><th>病名</th><th>ICD编码</th><th>操作</th></tr></thead><tbody>';
                $.each(xbsGroupData[q].diagnose, function (I, V) {
                    zdStr += '<tr><td>' + V.name + ' <input type="hidden" name="diagnose[]" value="' + V.id + '"></td>' +
                        '<td>' + V.icd + '</td><td>';
                    if (GroupBoxId == 'addSzBox') {
                        zdStr += '<button type="button" class="btn btn-outline btn-danger deleteDiagnosisBtn">删除</button></td></tr>';
                    }
                    else if (GroupBoxId == 'szFixedGroup') {
                        zdStr += '<button type="button" class="btn btn-outline btn-danger deleteDiagnosisBtn disabled" disabled>删除</button></td></tr>';
                    }
                });
                zdStr += '</tbody></table>';
                xbsGroupDiv.find('div.xbsAddDiagnosis').html(zdStr);
                if (GroupBoxId == 'szFixedGroup') {
                    xbsGroupDiv.find('div.table-title-diagnosis').html('诊断');
                }
            }
            //放置添加诊断表格数据  E
            //放置添加用药数据  S
            if (xbsGroupData[q].medication) {
                var medicationStr = '<table class="table-bordered table-striped table-hover text-center medicationList-table"><thead><tr><th>开始时间</th><th>结束时间</th><th>名称</th><th>剂量</th><th>单位</th><th>用法</th><th>频次</th><th>其他备注</th><th>操作</th></tr></thead><tbody>';
                for (var n = 0; n < xbsGroupData[q].medication.length; n++) {
                    medicationStr += '<tr class="medication' + (n + 1) + '">' +
                        '<td>' + checkUndefined(xbsGroupData[q].medication[n].start_time) + '<input type="hidden" value="' + xbsGroupData[q].medication[n].start_time + '" class="drugsdate" name="drugsdate[]"></td>' +
                        '<td>' + checkUndefined(xbsGroupData[q].medication[n].end_time) + '<input type="hidden" value="' + xbsGroupData[q].medication[n].end_time + '" class="drugsenddate" name="drugsenddate[]"></td>' +
                        '<td>' + checkUndefined(xbsGroupData[q].medication[n].name) + '<input type="hidden" value="' + xbsGroupData[q].medication[n].name + '" class="drugsid" name="drugsid[]"></td>';
                    if (xbsGroupData[q].medication[n].dosage.type == '每次剂量') {
                        medicationStr += '<td>' + checkUndefined(xbsGroupData[q].medication[n].dosage.value) + '<input type="hidden" class="dose" value="' + xbsGroupData[q].medication[n].dosage.value + '" name="dose[]"></td>';
                    } else if (xbsGroupData[q].medication[n].dosage.type == '分次剂量') {
                        medicationStr += '<td><span>早上' + checkUndefined(xbsGroupData[q].medication[n].dosage.values.morning) + '</span><input type="hidden" class="morning" value="' + xbsGroupData[q].medication[n].dosage.values.morning + '" name="morning[]"> ' +
                            '<span> 中午' + checkUndefined(xbsGroupData[q].medication[n].dosage.values.atnoon) + '</span><input type="hidden" class="atnoon" value="' + xbsGroupData[q].medication[n].dosage.values.atnoon + '" name="atnoon[]"> ' +
                            '<span> 晚上' + checkUndefined(xbsGroupData[q].medication[n].dosage.values.evening) + '</span><input type="hidden" class="evening" value="' + xbsGroupData[q].medication[n].dosage.values.evening + '" name="evening[]"> ' +
                            '<span> 睡前' + checkUndefined(xbsGroupData[q].medication[n].dosage.values.before_sleep) + '</span><input type="hidden" class="sleep" value="' + xbsGroupData[q].medication[n].dosage.values.before_sleep + '" name="sleep[]"></td>';
                    }
                    medicationStr += '<td>' + xbsGroupData[q].medication[n].dosage.unit + ' <input type="hidden" class="unit" value="' + xbsGroupData[q].medication[n].dosage.unit + '" name="unit[]"></td>' +
                        '<td>' + checkUndefined(xbsGroupData[q].medication[n].usage) + '<input type="hidden" class="usage" value="' + xbsGroupData[q].medication[n].usage + '" name="usage[]"></td>' +
                        '<td>' + checkUndefined(xbsGroupData[q].medication[n].frequency) + '<input type="hidden" class="frequency" value="' + xbsGroupData[q].medication[n].frequency + '" name="frequency[]"></td>' +
                        '<td>' + checkUndefined(xbsGroupData[q].medication[n].remark) + '<input type="hidden" class="remark" value="' + xbsGroupData[q].medication[n].remark + '" name="remark[]"></td>';
                    if (GroupBoxId == 'addSzBox') {
                        medicationStr += '<td><button type="button" class="btn btn-outline btn-primary margin-right-5 editMedicationBtn" data-toggle="modal" data-target="#addMedication" data-id="szAddMedication' + q + '" data-edit="medication' + (n + 1) + '">编辑</button>' +
                            '<button type="button" class="btn btn-outline btn-danger addMedicationDelete">删除</button></td></tr>';
                    }
                    else if (GroupBoxId == 'szFixedGroup') {
                        medicationStr += '<td><button type="button" class="btn btn-outline btn-primary margin-right-5 editMedicationBtn disabled" disabled data-toggle="modal" data-target="#addMedication" data-id="szAddMedication' + q + '" data-edit="medication' + (n + 1) + '">编辑</button>' +
                            '<button type="button" class="btn btn-outline btn-danger addMedicationDelete disabled" disabled>删除</button></td></tr>';
                    }
                }
                medicationStr += '</tbody></table>';
                xbsGroupDiv.find('div.xbsAddMedication').html(medicationStr);
                if (GroupBoxId == 'szFixedGroup') {
                    xbsGroupDiv.find('div.table-title-medication').html('西药');
                }
            }
            //放置添加用药数据  E
            //放置汤药详情数据  S
            //这里面加上容错，当后台返回数据为xbsGroupData[q].cn_medication时，则不存在.length
            if (xbsGroupData[q].cn_medication && xbsGroupData[q].cn_medication.length) {
                var tcmStr = '<table class="table-bordered table-striped table-hover text-center tcm-table"><thead><tr><th>名称剂量</th><th>煎服方法</th><th>操作</th></tr></thead><tbody>';
                $.each(xbsGroupData[q].cn_medication, function (I, V) {

                    if (V.type != 3) {
                        tcmStr += '<tr class="tcm' + (I + 1) + '"><td>';
                        for (var s = 0; s < V.drugs.length; s++) {
                            tcmStr += '<span>' + checkUndefined(V.drugs[s].name) + checkUndefined(V.drugs[s].weight) + 'g <input type="hidden" value="' + checkUndefined(V.drugs[s].name) + '" class="tableSelectTcm" data-num="' + checkUndefined(V.drugs[s].weight) + '"></span>'
                        }
                        tcmStr += '</td><td>煎法：' + checkUndefined(V.usage) + ' 频次：' + checkUndefined(V.dosage) + '，' + checkUndefined(V.frequency) + ' 总数：' + checkUndefined(V.dose) + '付' +
                            '<input type="hidden" class="takMethod" value="' + checkUndefined(V.usage) + '">' +
                            '<input type="hidden" class="frequency1" value="' + checkUndefined(V.dosage) + '">' +
                            '<input type="hidden" class="frequency2" value="' + checkUndefined(V.frequency) + '">' +
                            '<input type="hidden" class="total" value="' + checkUndefined(V.dose) + '"></td><td>';
                        if (GroupBoxId == 'addSzBox') {
                            tcmStr += '<button type="button" class="btn btn-outline btn-primary margin-right-5 addTcmEdit" data-toggle="modal" data-target="#addTcm" data-id="szAddTcm' + q + '" data-edit="tcm' + (I + 1) + '">编辑</button>' +
                                '<button type="button" class="btn btn-outline btn-danger addTcmDelete">删除</button></td></tr>';
                        }
                        else if (GroupBoxId == 'szFixedGroup') {
                            tcmStr += '<button type="button" class="btn btn-outline btn-primary margin-right-5 addTcmEdit disabled" disabled data-toggle="modal" data-target="#addTcm" data-id="szAddTcm' + q + '" data-edit="tcm' + (I + 1) + '">编辑</button>' +
                                '<button type="button" class="btn btn-outline btn-danger addTcmDelete disabled" disabled>删除</button></td></tr>';
                        }
                    } else {
                        var title = V.name;
                        var times = V.times_per_day;
                        var numMe = V.quantity_per_times;
                        var boxNum = V.total;
                        var stime = V.start_time;
                        var etime = V.end_time;
                        var unit = V.quantity_unit;
                        tcmStr += '<tr class="tcm' + (I + 1) + '" data-type="3" ><td><span>' + title +
                            '<input type="hidden" value="' + title + '" class="tableSelectTcm"></span>';

                        var sDataText, eDataText;
                        sDataText = (stime !== "") ? ( "， 开始时间：") : "";
                        eDataText = (etime !== "") ? (" 结束时间：") : "";
                        tcmStr += '</td><td>每日：' + times + ' 次， 每次：' + numMe + unit + '，总数：' + boxNum + '盒' + sDataText + stime + eDataText + etime +
                            '<input type="hidden" class="stime" value="' + stime + '">' +
                            '<input type="hidden" class="etime" value="' + etime + '">' +
                            '<input type="hidden" class="times" value="' + times + '">' +
                            '<input type="hidden" class="numMe" value="' + numMe + '"><' +
                            'input type="hidden" class="unit" value="' + unit + '"><' +
                            'input type="hidden" class="boxNum" value="' + boxNum + '"></td>';
                        tcmStr += '<td class="">' +
                            '<button type="button" class="btn btn-outline btn-primary margin-right-5 addTcmEdit"  data-toggle="modal" data-target="#addTcm" data-id="xbsAddTcm' + q + '" data-edit="tcm' + (I + 1) + '">编辑</button>' +
                            '<button type="button" class="btn btn-outline btn-danger addTcmDelete">删除</button></td>';

                    }


                });
                tcmStr += '</tbody></table>';
                xbsGroupDiv.find('div.xbsAddTcm').html(tcmStr);
                if (GroupBoxId == 'szFixedGroup') {
                    xbsGroupDiv.find('div.table-title-tcm').html('汤药');
                }
            }
            //放置汤药详情数据  E
        }


    }

    //随诊  放置函数end
    //标签点击 请求数据  start
    $('#addCaseNavTabs li[data-js="caseVisit"]').click(function () {
        var isSave = $(this).attr('data-save');
        var isLoad = $(this).attr('data-load');
        var tabPage = $(this).attr('data-href');
        if ((isLoad == 'no') && (isSave == 'yes')) {
            beforeGetData(tabPage);
        }
    });//标签点击 请求数据  end


    //主要症状列表  数据  start
    var MainSymptomsList = [];
    var MainSymptomsStr = '';
    var MainthyHBList = {};

    function strAdd(selected, data, addId) {
        var MainthyHBsStr = '';
        MainSymptomsStr = "";
        MainSymptomsStrThyroid = "";//添加主要症状 弹框中甲状腺对应的内容字符串
        var thyHBarr = [];
        var ArrEach = [];
        if (addId.indexOf('thyHB') >= 0) {
            if (addId == "thyHB1") {
                ArrEach = MainthyHBList.thyroid.symptoms;
            } else if (addId == "thyHB2") {
                ArrEach = MainthyHBList.thyroid.examination
            } else if (addId == "thyHB3") {
                ArrEach = MainthyHBList.thyroid.hyperthyroidism
            } else if (addId == "thyHB4") {
                ArrEach = MainthyHBList.adrenal.symptoms
            } else if (addId == "thyHB5") {
                ArrEach = MainthyHBList.adrenal.accompanied_symptom
            }
            $.each(ArrEach, function (k, v) {
                MainthyHBsStr += '<div class="lable-item"><label><input type="checkbox" value="' + v.value + '" checked="checked" id="' + v.id + '">' + v.value + '</label></div>'
            });
            $('#addSymptom .modal-body').html('<div class="addModel-group"><h4>常见症状</h4>' + MainthyHBsStr + '</div>');
        } else {
            for (var i = 0; i < MainSymptomsList.sysmpots.length; i++) {
                // MainSymptomsStr='';
                MainSymptomsStr += '<div class="addModel-group">' +
                    '<h4>' + MainSymptomsList.sysmpots[i].title + '</h4>';
                if (MainSymptomsList.sysmpots[i].data) {
                    for (var s = 0; s < MainSymptomsList.sysmpots[i].data.length; s++) {
                        MainSymptomsStr += '<div class="lable-item"><label>' +
                            '<input type="checkbox" value="' + MainSymptomsList.sysmpots[i].data[s].name + '" checked="checked" id="symptomName_' + MainSymptomsList.sysmpots[i].data[s].id + '">' + MainSymptomsList.sysmpots[i].data[s].name + '</label></div>';
                    }
                }
                MainSymptomsStr += '</div>';
            }

            MainSymptomsStrThyroid += '<div class="addModel-group">' +
                '<h4>' + '最常见症状' + '</h4>';
            for (var i = 0; i < MainSymptomsList.thyroidData.length; i++) {
                // MainSymptomsStr='';

                // if (MainSymptomsList.thyroidData[i].data) {
                //     for (var s = 0; s < MainSymptomsList.thyroidData[i].data.length; s++) {
                MainSymptomsStrThyroid += '<div class="lable-item"><label>' +
                    '<input type="checkbox" value="' + MainSymptomsList.thyroidData[i].name + '" checked="checked" id="symptomName_' + MainSymptomsList.thyroidData[i].id + '">' + MainSymptomsList.thyroidData[i].name + '</label></div>';
                // }
                // }
            }
            MainSymptomsStrThyroid += '</div>';

            $('#addSymptom .modal-body').html(MainSymptomsStr);

            // v15 ⬇
            $('#addSymptom .modal-body-thyroid').html(MainSymptomsStrThyroid);//甲状腺


        }
        if (selected) {
            for (var s = 0; s < selected.length; s++) {
                $('#addSymptom .modal-body-main').find('input[value="' + selected[s].name + '"]').parent().parent().addClass('current');
            }
        }

        // v14以及之前的版本容错，线上也有此问题，改正开始（返回数据没有id，这里自己从页面遍历加id）； ⬇
        selected=[];
        $.each($(".modal-body-main .current input"),function(z,x){
            "use strict";
            selected.push({id:$(x).attr('id'),name:$(x).val()})
        });
        selectedSymptomList=selected;
        // v14以及之前的版本容错，线上也有此问题，改正开始（返回数据没有id，这里自己从页面遍历加id）； ⬆

    };

    // V15 首诊选择症状 搜索 切换tab等操作⬇
    var diseSearchInput = $("#diseSearchInput");


    $(".diseaseTabLi").click(function () {
        "use strict";
        if (!$(this).hasClass('active')) {

            $(this).addClass('active').siblings('.diseaseTabLi').removeClass('active');
            if ($(".thyroidTabLi").hasClass('active')) {//甲状腺被选中
                $(".modal-body-thyroid").show();
                $(".modal-body").hide();
            } else {
                $(".modal-body-thyroid").hide();
                $(".modal-body").show();
            }
        }

    });


    // V15 首诊选择症状 搜索 切换tab等操作⬆

    function getMainSymptoms(selected, addId) {
        var getUrl = '';
        if (addId.indexOf('thyHB') >= 0) {
            getUrl = '/manage/hpi/symptoms/items';
            if (JSON.stringify(MainthyHBList) !== '{}') {
                strAdd(selected, MainthyHBList, addId)
            } else {
                $.get(getUrl, function (data) {
                    if (data.code === 10000) {
                        MainthyHBList = data.data;
                        strAdd(selected, MainthyHBList, addId)
                    } else if (data.code === 40100) {
                        aClick();
                    } else {
                        alertModel('', data.message);
                    }

                })
            }

        } else {
            getUrl = '/manage/symptom/list';
            if (MainSymptomsList.length > 0) {
                strAdd(selected, MainSymptomsList, addId)
            } else {
                $.get(getUrl, function (data) {
                    if (data.code === 10000) {
                        MainSymptomsList = data.data;
                        strAdd(selected, MainSymptomsList, addId);
                    } else if (data.code === 40100) {
                        aClick();
                    } else {
                        alertModel('', data.message);
                    }

                })

            }

        }


    }//主要症状列表  数据  end


    // function getMainSymptoms(selected) {
    //     $.get('/manage/symptom/list', function (data) {
    //         if (data.code === 10000) {
    //             MainSymptomsList = data.data;
    //             for (var i = 0; i < MainSymptomsList.length; i++) {
    //                 MainSymptomsStr += '<div class="addModel-group">' +
    //                     '<h4>' + MainSymptomsList[i].title + '</h4>';
    //                 for (var s = 0; s < MainSymptomsList[i].data.length; s++) {
    //                     MainSymptomsStr += '<div class="lable-item"><label>' +
    //                         '<input type="checkbox" value="' + MainSymptomsList[i].data[s].name + '" checked="checked" id="symptomName_' + MainSymptomsList[i].data[s].id + '">' + MainSymptomsList[i].data[s].name + '</label></div>';
    //                 }
    //                 MainSymptomsStr += '</div>';
    //             }
    //             $('#addSymptom .modal-body').html(MainSymptomsStr);
    //             if (selected) {
    //                 for (var s = 0; s < selected.length; s++) {
    //                     $('#addSymptom .modal-body').find('input[value="' + selected[s].name + '"]').parent().parent().addClass('current');
    //                 }
    //             }
    //         } else if (data.code === 40100) {
    //             aClick();
    //         } else {
    //             alertModel('', data.message);
    //         }
    //     });
    // }//主要症状列表  数据  end

    //主要症状弹出框 症状名字点击事件  start
    var selectedSymptomList = [];
    $('#addSymptom .modal-body-main').delegate('div.lable-item input', 'click', function () {

        // selectedSymptomList=selectedMiddle;
        var divBox = $(this).parent().parent();

        if (divBox.hasClass('current')) {
            for (var i = 0; i < selectedSymptomList.length; i++) {
                if (selectedSymptomList[i].id == $(this).attr('id')) {
                    selectedSymptomList.splice(i, 1);
                }
            }
            divBox.removeClass('current');
        } else {
            if (selectedSymptomList.length >= 5) {
                $.alert({
                    title: '温馨提示',
                    body: '主要症状最多可选5个！',
                    transition: true,
                    okHidden: function () {
                        $('.sui-modal-backdrop.fade.in').removeClass('alertZindex');
                    }
                });
                $('.sui-modal-backdrop.fade.in').addClass('alertZindex');
            } else {
                selectedSymptomList.push({name: $(this).val(), id: $(this).attr('id')});
                divBox.addClass('current');
            }
        }
    });//主要症状弹出框 症状名字点击事件  end

    // V15 首诊选择症状 搜索 切换tab等操作⬇
    var selectedMiddle = [];
    var diseSearchInput = $("#diseSearchInput");
    $(".diseSearchInputBtn").click(function () {
        "use strict";
        if (diseSearchInput.val() == '') {
            if ($(".thyroidTabLi").hasClass('active')) {//甲状腺被选中
                $(".modal-body-thyroid").show();
                $(".modal-body").hide();
            } else {
                $(".modal-body-thyroid").hide();
                $(".modal-body").show();
            }
            $(".modal-body-search").hide();
            $(".diseaseTab").show();

        } else {

            //正常放在成功后的回调函数中
            $(".modal-body-search").show();
            $(".modal-body-thyroid").hide();
            $(".modal-body").hide();
            $(".diseaseTab").hide();
            //正常放在成功后的回调函数中

            ajax('post', '/manage/symptom/lists', {name: diseSearchInput.val()}, function (data) {
                    if (data.code = 10000) {
                        var MainSymptomsList = data.data;
                        var addId = $("#saveSymptom").attr('data-id');
                        var ulList = $('#' + addId).find('ul.sui-tag li');
                        var selected = [];  //存放已选择的症状
                        selectedMiddle = [];  //存放已选择的症状 中间件数组
                        // selectedMiddle.concat(selected);

                        selectedSymptomList = selected;
                        // if (addId.indexOf("thyHB") >= 0) {
                        //     ulList = $("button." + addId).parents("div.ibox").find('ul.sui-tag li');
                        // }

                        for (var i = 0; i < ulList.length; i++) {
                            selected.push({name: ($(ulList[i])).attr('data-name'), id: ($(ulList[i])).attr('data-id')});
                        }

                        $.each($("#addSymptom .modal-body-main .lable-item.current"), function (m, n) {
                            selectedMiddle.push({
                                name: $(n).find('input').val(),
                                id: $(n).find('input').attr('id').slice(12)
                            });
                        });
                        selectedSymptomList = selectedMiddle;
                        var MainthyHBsStr = '';
                        var MainSymptomsStr = "";
                        var MainSymptomsStrThyroid = "";//添加主要症状 弹框中甲状腺对应的内容字符串
                        var thyHBarr = [];
                        var ArrEach = [];

                        if (addId.indexOf('thyHB') >= 0) {
                            if (addId == "thyHB1") {
                                ArrEach = MainthyHBList.thyroid.symptoms;
                            } else if (addId == "thyHB2") {
                                ArrEach = MainthyHBList.thyroid.examination
                            } else if (addId == "thyHB3") {
                                ArrEach = MainthyHBList.thyroid.hyperthyroidism
                            } else if (addId == "thyHB4") {
                                ArrEach = MainthyHBList.adrenal.symptoms
                            } else if (addId == "thyHB5") {
                                ArrEach = MainthyHBList.adrenal.accompanied_symptom
                            }
                            $.each(ArrEach, function (k, v) {
                                MainthyHBsStr += '<div class="lable-item"><label><input type="checkbox" value="' + v.value + '" checked="checked" id="' + v.id + '">' + v.value + '</label></div>'
                            });
                            $('#addSymptom .modal-body').html('<div class="addModel-group"><h4>常见症状</h4>' + MainthyHBsStr + '</div>');
                        }
                        else {

                            if (MainSymptomsList.sysmpots.length) {
                                MainSymptomsStr += '<div class="addModel-group">' +
                                    '<h4>糖尿病</h4>';
                                for (var s = 0; s < MainSymptomsList.sysmpots.length; s++) {
                                    var sta = 0;
                                    $.each(selectedMiddle, function (o, p) {
                                        if (MainSymptomsList.sysmpots[s].id == p.id) {
                                            sta = 1;
                                            // break;
                                        }
                                    });
                                    if (sta) {//默认选中
                                        MainSymptomsStr += '<div class="lable-item current"><label>' +
                                            '<input type="checkbox" value="' + MainSymptomsList.sysmpots[s].name + '" checked="checked" id="symptomName_' + MainSymptomsList.sysmpots[s].id + '">' + MainSymptomsList.sysmpots[s].name + '</label></div>';

                                    } else {//不选中
                                        MainSymptomsStr += '<div class="lable-item"><label>' +
                                            '<input type="checkbox" value="' + MainSymptomsList.sysmpots[s].name + '" checked="checked" id="symptomName_' + MainSymptomsList.sysmpots[s].id + '">' + MainSymptomsList.sysmpots[s].name + '</label></div>';

                                    }
                                }
                                MainSymptomsStr += '</div>';
                            }

                            if (MainSymptomsList.thyroidData.length) {
                                MainSymptomsStrThyroid += '<div class="addModel-group">' +
                                    '<h4>甲状腺</h4>';
                                for (var i = 0; i < MainSymptomsList.thyroidData.length; i++) {
                                    var staT = 0;
                                    $.each(selectedMiddle, function (o, p) {
                                        if (MainSymptomsList.thyroidData[i].id == p.id) {
                                            staT = 1;
                                        }
                                    });
                                    if (staT) {
                                        MainSymptomsStrThyroid += '<div class="lable-item current"><label>' +
                                            '<input type="checkbox" value="' + MainSymptomsList.thyroidData[i].name + '" checked="checked" id="symptomName_' + MainSymptomsList.thyroidData[i].id + '">' + MainSymptomsList.thyroidData[i].name + '</label></div>';

                                    } else {
                                        MainSymptomsStrThyroid += '<div class="lable-item"><label>' +
                                            '<input type="checkbox" value="' + MainSymptomsList.thyroidData[i].name + '" checked="checked" id="symptomName_' + MainSymptomsList.thyroidData[i].id + '">' + MainSymptomsList.thyroidData[i].name + '</label></div>';

                                    }

                                }
                                MainSymptomsStrThyroid += '</div>';
                            }


                            $('#addSymptom .modal-body-search').html(MainSymptomsStr + MainSymptomsStrThyroid);//搜索

                        }

                        if (selected) {
                            for (var s = 0; s < selected.length; s++) {
                                $('#addSymptom .modal-body').find('input[value="' + selected[s].name + '"]').parent().parent().addClass('current');
                            }
                        }


                    }
                }
            )
        }

    });

    $('#addSymptom .modal-body-search').delegate('.lable-item input', 'click', function () {
        "use strict";
        var id = $(this).attr('id').slice(12);
        var name = $(this).val();
        if ($(this).parents('.lable-item').hasClass('current')) {
            $.each(selectedMiddle, function (k, v) {
                if (v.id == id) {
                    selectedMiddle.splice(k, 1);
                    return false; //退出循环；
                    // return selectedMiddle;
                }

            });
            $.each($("#addSymptom .modal-body-main .lable-item.current"), function (z, x) {
                if ($(x).find('input').attr('id').slice(12) == id) {
                    $(x).removeClass('current');
                    return false;
                }

            })
            $(this).parents('.lable-item').removeClass('current');

        } else {
            if (selectedMiddle.length >= 5) {
                alertModel('温馨提示', '主要症状最多可选5个！')
            } else {
                selectedMiddle.push({id: id, name: name});
                $.each($("#addSymptom .modal-body-main .lable-item"), function (z, x) {
                    if ($(x).find('input').attr('id').slice(12) == id) {
                        $(x).addClass('current');
                        return false;

                    }
                });
                $(this).parents('.lable-item').addClass('current');
            }


        }


    });

    $(".diseaseTabLi").click(function () {
        "use strict";
        if (!$(this).hasClass('active')) {

            $(this).addClass('active').siblings('.diseaseTabLi').removeClass('active');
            if ($(".thyroidTabLi").hasClass('active')) {//甲状腺被选中
                $(".modal-body-thyroid").show();
                $(".modal-body").hide();
            } else {
                $(".modal-body-thyroid").hide();
                $(".modal-body").show();
            }
        }

    });


        // V15 首诊选择症状 搜索 切换tab等操作⬆


    //主要症状弹出框 添加症状按钮点击事件  start
    $('#saveSymptom').click(function () {
        var id = $(this).attr('data-id');
        var str = '';
        for (var i = 0; i < selectedSymptomList.length; i++) {
            str += '<li class="tag-selected with-x" data-id="' + selectedSymptomList[i].id + '" data-name="' + selectedSymptomList[i].name + '"><input type="hidden" value="' + selectedSymptomList[i].name + '" name="symptom[]">' + selectedSymptomList[i].name + '<i>×</i></li>'
        }
        if (id.indexOf('thyHB') >= 0) {
            $("button." + id).parents("div.ibox").find('ul.sui-tag').html(str)
        } else {
            $('#' + id).find('ul.sui-tag').html(str);

        }
    });//主要症状弹出框 添加症状按钮点击事件  end


    //随诊  添加抓药症状按钮  start
    $('.tab-content').delegate('.add-symptom', 'click', function () {
        //此处添加弹框初始化处理⬇v15
        $(".modal-body-thyroid").hide();
        $(".modal-body").show();
        $("#diseSearchInput").val('');
        $(".diseaseTab").show();
        $(".diseaseTabLi").addClass('active');
        if($(".thyroidTabLi").hasClass('active')){
            $(".thyroidTabLi").removeClass('active');
        };
        $('.modal-body-search').hide().html('');


        var addSymptom_modal = $('#addSymptom .modal-body');  //弹出框的放置内容的父元素
        addSymptom_modal.html("");
        var addId = $(this).attr('data-id');  //获取点击的是那一组
        $('#saveSymptom').attr('data-id', addId);  //把症状组编码放入添加模态框保存按钮做记号
        var ulList = $('#' + addId).find('ul.sui-tag li');
        var selected = [];  //存放已选择的症状
        selectedSymptomList = selected;
        if (addId.indexOf("thyHB") >= 0) {
            ulList = $("button." + addId).parents("div.ibox").find('ul.sui-tag li');
        }

        for (var i = 0; i < ulList.length; i++) {
            selected.push({name: ($(ulList[i])).attr('data-name'), id: ($(ulList[i])).attr('data-id')});
        }


        if ((ulList.length) === 0) {  //判断改组症状是否已经选择了5个

            // if (MainSymptomsList.length == 0) {
            getMainSymptoms([], addId);
            // }
            // else {
            //     addSymptom_modal.html(MainSymptomsStr);
            // }
        } else if ((ulList.length) <= 5) {
            // if (MainSymptomsList.length == 0) {

            getMainSymptoms(selected, addId);
            // }
            // else {
            //     addSymptom_modal.html(MainSymptomsStr);
            //     for (var s = 0; s < selected.length; s++) {
            //         $('#addSymptom .modal-body').find('input[value="' + selected[s].name + '"]').parent().parent().addClass('current');
            //     }
            // }
        }
    });//主诉 现病史  添加症状点击按钮  end
    //随诊  页面上已经选择的症状删除 操作  start
    $('#suizhen').delegate('ul.sui-tag li', 'click', function () {
        var _this = $(this);
        confirmModel('', '', '', '', function () {
            _this.remove();
        });
    });//随诊  页面上已经选择的症状删除 操作  end
    //随诊  体重变化选择改变事件  start
    $('.zsWeightChangeSelect').change(function () {
        var zsWeightChangeSize = $('.zsWeightChangeSize.szWeightChangeSize');
        if ($(this).val() == 0) {
            zsWeightChangeSize.hide(300);
            zsWeightChangeSize.find('input').val('');
        } else {
            zsWeightChangeSize.show(300);
        }
    });//随诊  体重变化选择改变事件  end
    //随诊  添加一组随诊按钮  start
    $('#addSzGroup').click(function () {
        var ZsGroupDiv = $('#addSzBox>div');
        for (var i = 0; i < ZsGroupDiv.length; i++) {
            var isHidden = $(ZsGroupDiv[i]).css('display');
            if (isHidden == 'none') {
                $(ZsGroupDiv[i]).show(300);
                checkNum(ZsGroupDiv, 'addSzGroup', 5);
                break;
            }
        }
    });//现病史  添加一组随诊按钮  end
    //随诊  追加的随诊组 删除按钮  start
    $('#addSzBox').delegate('.szAddGroupDelete', 'click', function () {
        var id = $(this).attr('data-group');
        var xbsGroupId = $('#' + id).find('input.szGroupId').val();
        confirmModel('温馨提示', '确认要删除吗？', '确定', '取消', function () {
            if (xbsGroupId) {
                szDeleteGroup(xbsGroupId, id);
            } else {
                $('#' + id).hide(300);
                $('#' + id).find('ul.sui-tag').html('');
                $('#' + id).find('div.szGroupTable').html('');
                $('#' + id).find('input').val('');
                $('#' + id).find('select').val('1');
            }
            if ($('#addSzGroup').hasClass('disabled')) {
                $('#addSzGroup').removeClass('disabled');
                $('#addSzGroup').removeAttr('disabled');
            }
        });
    });

    function szDeleteGroup(xbsGroupId, id) {   //现病史  删除数据库
        $.post('/manage/hpiSub/destroy/' + xbsGroupId, {_method: 'DELETE'}, function (data) {
            if (data.code == 10000) {
                $('#' + id).hide(300);
                $('#' + id).find('ul.sui-tag').html('');
                $('#' + id).find('div.szGroupTable').html('');
                $('#' + id).find('input').val('');
                $('#' + id).find('select').val('1');
                alertModel('', '删除成功！');
            } else if (data.code === 40100) {
                aClick();
            } else {
                alertModel('', data.message);
            }
        });
    }

    //随诊  追加的随诊组 删除按钮  end
    //随诊  保存方法  start
    function szSaveFun(url, result, idInputParent, idInput, pop, NEXT, activeID) {
        ajaxPost(url, result, function (data) {
            if (data.code == 10000) {
                saveSeccessTab();
                var szGroupId = $('#' + idInputParent + ' input.' + idInput).val();
                if (data.data && data.data.id) {
                    $('#' + idInputParent + ' input.' + idInput).val(data.data.id);
                    if (idInput == 'szGroupId') {
                        if ($('#' + idInputParent + ' div.szGroupSaveBox').hasClass('display-none')) {
                            $('#' + idInputParent + ' div.szGroupSaveBox').removeClass('display-none');
                        }
                    }
                }
                if (isjump === 1) {
                    //判断如果需要跳转监测血糖 则直接跳转
                    document.getElementById("monitoringBlood").click();
                    isjump = 0;
                    return;
                }
                if (pop || szGroupId) {
                    if (NEXT == 'NEXT') {
                        activeID.click();
                        scrollTo(0, 0);
                    } else {
                        $.alert({
                            title: '温馨提示',
                            body: '保存成功！',
                            transition: true,
                            okHidden: function () {
                                // if (next) {
                                //     saveNext();  //跳转至下一页
                                // }
                            }
                        });
                    }

                }
            } else if (data.code === 40100) {
                aClick();
            } else {
                alertModel('', '保存失败！');
            }
        }, function (x, t, e) {
            if (x.status != 422) {
                alertModel('', '保存失败，再来一次吧！');
            }
        })
    } //随诊  保存方法  end
    //随诊  自我血糖检测 到 一般情况  提交前整理数据  start
    function szFinishingData(NEXT, activeID) {
        var szData = {};//存储随诊数据
        szData.thyroid = {};//创建甲状腺对象
        szData.adrenal_gland = {};//创建高血压肾上腺对象
        szData.thyroid.symptoms = [];//甲状腺起病症状数组
        szData.thyroid.examination = [];//甲状腺化验检查数组
        szData.thyroid.hyperthyroidism = [];//甲状腺相关症状数组
        szData.adrenal_gland.symptoms = [];//高血压主要症状
        szData.adrenal_gland.accompanied_symptom = [];//高血压伴随症状
        //获取自我血糖检测情况数据  S
        szData.blood_glucose = {};
        var bloodGlucoseDiv = $('#suizhen div.blood_glucose div[data-name]');
        for (var q = 0; q < bloodGlucoseDiv.length; q++) {
            var bloodGlucoseDivKey = $(bloodGlucoseDiv[q]).attr('data-name');
            szData.blood_glucose[bloodGlucoseDivKey] = {};
            var bloodGlucoseDivInput = $(bloodGlucoseDiv[q]).find('input');
            for (var w = 0; w < bloodGlucoseDivInput.length; w++) {
                var inputKey = $(bloodGlucoseDivInput[w]).attr('data-name');
                var inputVal = $(bloodGlucoseDivInput[w]).val();
                var bloodArr = [];
                if (inputVal) {
                    bloodArr.push(inputVal)
                }
                if (checkBloodNum(bloodArr)) {
                    szData.blood_glucose[bloodGlucoseDivKey][inputKey] = inputVal;
                } else {
                    alertModel('', '请正确填写 自我血糖监测情况 的血糖值！');
                    return false;
                }
            }
        }


        //获取自我血糖检测情况数据  E
        //获取 上次就诊至本次就诊间隔情况评价 数据  S
        var intervalEvaluationDiv = $('#suizhen div.interval_evaluation');
        szData.interval_evaluation = {};
        szData.interval_evaluation.remark = intervalEvaluationDiv.find('input.remark').val();
        szData.interval_evaluation.blood_glucose = intervalEvaluationDiv.find('div.blood_glucose input:checked').val();
        szData.interval_evaluation.hypoglycemia = intervalEvaluationDiv.find('div.hypoglycemia input:checked').val();
        szData.interval_evaluation.weight = {};
        var weight_change = intervalEvaluationDiv.find('select.zsWeightChangeSelect').val();
        szData.interval_evaluation.weight.change = weight_change;
        if (weight_change != 0) {
            szData.interval_evaluation.weight.effect = intervalEvaluationDiv.find('select.zsWeightchangestatus').val();
            if (szData.interval_evaluation.weight.effect == 1) {
                szData.interval_evaluation.weight.kg = intervalEvaluationDiv.find('input.weightchangekg').val();
            }
        }
        //获取 上次就诊至本次就诊间隔情况评价 数据  E
        //获取 上次就诊至本次就诊间隔症状 数据  S
        szData.interval_symptom = {};
        szData.interval_symptom.remark = $('#suizhen div.interval_symptom input.remark').val();
        var symptomsInput = $('#szSymptom ul.interval_symptom input');
        if (symptomsInput.length > 0) {
            szData.interval_symptom.symptoms = [];
            for (var r = 0; r < symptomsInput.length; r++) {
                szData.interval_symptom.symptoms.push($(symptomsInput[r]).val());
            }
        } else {
            szData.interval_symptom.symptoms = '';
        }
        //获取 上次就诊至本次就诊间隔症状 数据  E

        // 获取一般情况数据  S

        // var generalTdList = $('#suizhen .xbs-table td[data-name]');
        // for (var i = 0; i < generalTdList.length; i++) {
        //     var tdKey = $(generalTdList[i]).attr('data-name');
        //     if (tdKey == 'sport') {
        //         szData[tdKey] = $(generalTdList[i]).find('.form-control').val();
        //     }
        //     else {
        //         szData[tdKey] = {};
        //         var generalTdDivList = $(generalTdList[i]).find('div[data-name]');
        //         for (var j = 0; j < generalTdDivList.length; j++) {
        //             var tdDivKey = $(generalTdDivList[j]).attr('data-name');
        //             var tdDivType = $(generalTdDivList[j]).attr('data-type');
        //             if (tdDivType == 'obj') {
        //                 if (!szData[tdKey][tdDivKey]) {
        //                     szData[tdKey][tdDivKey] = {};
        //                 }
        //                 szData[tdKey][tdDivKey][$(generalTdDivList[j]).find('.form-control').attr('data-name')] = $(generalTdDivList[j]).find('.form-control').val();
        //             } else {
        //                 if ($(generalTdDivList[j]).find('.form-control').attr('name')) {
        //                     var inputType = $(generalTdDivList[j]).find('.form-control').attr('type');
        //                     var val = $(generalTdDivList[j]).find('.form-control').val();
        //                     if (inputType == 'number') {
        //                         if (isNaN(val) || val < 0) {
        //                             alertModel('', '请正确填写' + $(generalTdDivList[j]).find('span:first-child').html() + '的数量');
        //                             return false;
        //                         } else {
        //                             szData[tdKey][tdDivKey] = val;
        //                         }
        //                     } else {
        //                         szData[tdKey][tdDivKey] = val;
        //                     }
        //                 } else {
        //                     szData[tdKey][tdDivKey] = $(generalTdDivList[j]).find('input:checked').val();
        //                 }
        //             }
        //         }
        //     }
        // }


        /***********************************/
        var generalTdList = $('#suizhen .xbs-table td[data-name]');
        for (var i = 0; i < generalTdList.length; i++) {
            var tdKey = $(generalTdList[i]).attr('data-name');
            if (tdKey == 'sport') {
                szData[tdKey] = $(generalTdList[i]).find('.form-control').val();
            } else {
                szData[tdKey] = {};
                var generalTdDivList = $(generalTdList[i]).find('div[data-name]');
                for (var j = 0; j < generalTdDivList.length; j++) {
                    var tdDivKey = $(generalTdDivList[j]).attr('data-name');
                    var tdDivType = $(generalTdDivList[j]).attr('data-type');
                    if (tdDivType == 'obj') {
                        if (!szData[tdKey][tdDivKey]) {
                            szData[tdKey][tdDivKey] = {};
                        }

                        szData[tdKey][tdDivKey][$(generalTdDivList[j]).find('.form-control').attr('data-name')] = $(generalTdDivList[j]).find('.form-control').val();
                    } else {
                        if ($(generalTdDivList[j]).find('.form-control').attr('name')) {
                            var inputType = $(generalTdDivList[j]).find('.form-control').attr('type');
                            var val = $(generalTdDivList[j]).find('.form-control').val();
                            if (inputType == 'number') {
                                if (isNaN(val) || val < 0) {
                                    alertModel('', '请正确填写' + $(generalTdDivList[j]).find('span:first-child').html() + '的数量');
                                    return false;
                                } else {
                                    szData[tdKey][tdDivKey] = val;
                                }
                            } else {
                                szData[tdKey][tdDivKey] = val;
                            }
                        } else {
                            szData[tdKey][tdDivKey] = $(generalTdDivList[j]).find('input:checked').val();
                        }
                    }
                }
            }
        }

        // v14 更改布局后的字段放入⬇
        szData['sport_strength'] = $(".sport_strength").val();
        szData['sport_time'] = $(".sport_time").val();


        szData['normal']['shit']['value'] = $(".shitNew input.value:checked").val();
        szData['normal']['shit']['remark'] = $(".shitNew input.shitNewRemark").val();
        szData['normal']['shit']['customFrequency'] = $(".shitNew input.customFrequency").val();

        szData['normal']['pee']['difficulty'] = $(".peeDif:checked").val();

        szData['normal']['sweat']['situation'] = $("input.sweatInput:checked").val();
        szData['normal']['sweat']['remark'] = $("input.sweatRemark").val();


        // v14 更改布局后的字段放入⬆
        /***********************************/



        // 获取一般情况数据  E
        szData['remark'] = $('#suizhen #szRemark').val();
        var szId = $('#suizhen input.szId').val();
        var url = '/manage/follow/store';
        if (szId) {
            url = '/manage/follow/update';
        }
        szData['id'] = szId;
        szData['record_id'] = record_id;

        //甲状腺数据推入⬇️；
        var thyroid = $("#thyroidParent");
        var adrenal_gland = $("#adrenal_glandParent");

        szData.thyroid.started_at = thyroid.find("input.thyroidStarted_at").val();
        szData.thyroid.inducement = thyroid.find("select.thyroidInducement").val();
        szData.thyroid.symptoms_remark = thyroid.find("input.thyroid_symptoms_remark").val();
        szData.thyroid.examination_remark = thyroid.find("input.examination_remark").val();
        szData.thyroid.hyperthyroidism_remark = thyroid.find("input.hyperthyroidism_remark").val();
        $.each($(".thyroid li"), function (k, v) {
            szData.thyroid.symptoms.push($(v).attr("data-name"));
        });
        $.each($(".thyroid1 li"), function (k, v) {
            szData.thyroid.examination.push($(v).attr("data-name"));
        });
        $.each($(".thyroid2 li"), function (k, v) {
            szData.thyroid.hyperthyroidism.push($(v).attr("data-name"));
        });

        //高血压⬇️
        szData.adrenal_gland.started_at = adrenal_gland.find("input.started_at").val();
        szData.adrenal_gland.symptoms_remark = adrenal_gland.find("input.symptoms_remark").val();
        szData.adrenal_gland.accompanied_symptom_remark = adrenal_gland.find("input.accompanied_symptom_remark").val();
        $.each($(".highBlood li"), function (k, v) {
            szData.adrenal_gland.symptoms.push($(v).attr("data-name"));
        });
        $.each($(".highBlood1 li"), function (k, v) {
            szData.adrenal_gland.accompanied_symptom.push($(v).attr("data-name"));
        });
        // console.log(szData);
        // if (next) {
        //     szSaveFun(url, szData, 'suizhen', 'szId', 'pop', 'next');
        // } else {
        szSaveFun(url, szData, 'suizhen', 'szId', 'pop', NEXT, activeID);
        // }
    } //随诊  自我血糖检测 到 一般情况  提交前整理数据  end
    //随诊 组  整理数据  start
    var generalSituation = true;//存储一般情况能否保存
    function szGroupData(id) {
        var hpiSub = {};
        //获取起病日期到症状数据
        var baseMessage = $('#' + id + ' div[data-name="hpiSub"] .updataBox');
        for (var i = 0; i < baseMessage.length; i++) {
            var key = $(baseMessage[i]).attr('data-name');
            var value = $(baseMessage[i]).find('.form-control').val();
            hpiSub[key] = value;
        }
        var symptomsInput = $('#' + id + ' .sui-tag input');
        hpiSub['symptoms'] = [];
        for (var j = 0; j < symptomsInput.length; j++) {
            hpiSub['symptoms'].push($(symptomsInput[j]).val());
        }
        if ((!hpiSub.started_at) || (!hpiSub.symptoms.length)) {
            alertModel('', '请填写随诊组的起病日期和起病症状！');
            return false;
        }
        //获取用药前和血糖后血糖值数据
        var bloodInput = $('#' + id + ' div.bloodInput');
        for (var s = 0; s < bloodInput.length; s++) {
            var bloodKey = $(bloodInput[s]).attr('data-name');
            hpiSub[bloodKey] = {};
            var bloodInputBox = $(bloodInput[s]).find('div[data-name]');
            for (var p = 0; p < bloodInputBox.length; p++) {
                var bloodInputBoxKey = $(bloodInputBox[p]).attr('data-name');
                if (bloodInputBoxKey == 'hba1c') {
                    var val = $(bloodInputBox[p]).find('.form-control').val();
                    if (val) {
                        if (isNaN(val) || val <= 0 || val > 99) {
                            alertModel('', '请正确填写HbA1c的值');
                            generalSituation = false;
                            return false;
                        } else {
                            hpiSub[bloodKey][bloodInputBoxKey] = val;
                        }
                    } else {
                        hpiSub[bloodKey][bloodInputBoxKey] = val;
                    }
                } else {
                    hpiSub[bloodKey][bloodInputBoxKey] = {};
                    var lowVal = $(bloodInputBox[p]).find('input[data-name="low"]').val();
                    var highVal = $(bloodInputBox[p]).find('input[data-name="high"]').val();
                    var bloodArr = [];
                    if (lowVal) {
                        bloodArr.push(lowVal)
                    }
                    if (highVal) {
                        bloodArr.push(highVal)
                    }
                    if (checkBloodNum(bloodArr)) {
                        hpiSub[bloodKey][bloodInputBoxKey]['low'] = lowVal;
                        hpiSub[bloodKey][bloodInputBoxKey]['high'] = highVal
                    } else {
                        alertModel('', '请正确填写血糖的值');
                        generalSituation = false;
                        return false;
                    }
                }
            }
        }
        //获取 汤药详情 的值  S
        if ($('#' + id + ' .hpiTcm').find('button.addTcmBtn').html()) {  //先判断是否有中医部分
            if ($('#' + id + ' .hpiTcm .xbsAddTcm').html().trim()) {
                hpiSub['cn_medication'] = [];
                var tcmTr = $('#' + id + ' .hpiTcm .xbsAddTcm tbody tr');
                if (tcmTr.length) {
                    for (var w = 0; w < tcmTr.length; w++) {
                        if ($(tcmTr[w]).attr("data-type") !== "3") {
                            var obj = {}, objDrugs = obj['drugs'] = [];
                            obj['usage'] = $(tcmTr[w]).find('input.takMethod').val();
                            obj['dosage'] = $(tcmTr[w]).find('input.frequency1').val();
                            obj['frequency'] = $(tcmTr[w]).find('input.frequency2').val();
                            obj['dose'] = $(tcmTr[w]).find('input.total').val();
                            obj['type'] = 1;
                            var tcmNameTds = $(tcmTr[w]).find('td:first-child input');
                            for (var p = 0; p < tcmNameTds.length; p++) {
                                objDrugs.push({
                                    'name': $(tcmNameTds[p]).val(),
                                    'weight': $(tcmNameTds[p]).attr('data-num')
                                });
                            }
                            hpiSub['cn_medication'].push(obj);
                        } else {
                            // todo 此处添加
                            var obj = {};
                            obj['name'] = $(tcmTr[w]).find('input.tableSelectTcm').val();//药名
                            obj['start_time'] = $(tcmTr[w]).find('input.stime').val();//开始时间
                            obj['end_time'] = $(tcmTr[w]).find('input.etime').val();//结束时间
                            obj['times_per_day'] = $(tcmTr[w]).find('input.times').val();//每一次数
                            obj['quantity_per_times'] = $(tcmTr[w]).find('input.numMe').val();//每次数量
                            obj['quantity_unit'] = $(tcmTr[w]).find('input.unit').val();//单位
                            obj['total'] = $(tcmTr[w]).find('input.boxNum').val();//总数
                            obj['type'] = 3;//总数

                            hpiSub['cn_medication'].push(obj);
                        }

                    }
                }
            } else {
                hpiSub['cn_medication'] = '';
            }
        }
        //获取 汤药详情 的值  E
        //获取 诊断 的值  S
        var diagnoseInput = $('#' + id + ' div.xbsAddDiagnosis input[type="hidden"]');
        hpiSub['diagnose'] = [];
        if (diagnoseInput.length) {
            for (var z = 0; z < diagnoseInput.length; z++) {
                if (hpiSub['diagnose'].indexOf($(diagnoseInput[z]).val()) == -1) {
                    hpiSub['diagnose'].push($(diagnoseInput[z]).val());
                }
            }
        } else {
            hpiSub.diagnose = '';
        }
        //获取 诊断 的值  E
        //获取 用药 的值  S
        hpiSub['medication'] = '';
        if ($('#' + id + ' div.xbsAddMedication').html().trim()) {
            hpiSub['medication'] = [];
            var medicationTrList = $('#' + id + ' div.xbsAddMedication tbody tr');
            for (var y = 0; y < medicationTrList.length; y++) {
                var object = {};
                object['name'] = $(medicationTrList[y]).find('input.drugsid').val();
                object['start_time'] = $(medicationTrList[y]).find('input.drugsdate').val();
                object['end_time'] = $(medicationTrList[y]).find('input.drugsenddate').val();
                object['usage'] = $(medicationTrList[y]).find('input.usage').val();
                object['frequency'] = $(medicationTrList[y]).find('input.frequency').val();
                object['remark'] = $(medicationTrList[y]).find('input.remark').val();
                object['dosage'] = {};
                object['dosage']['unit'] = $(medicationTrList[y]).find('input.unit').val();
                if ($(medicationTrList[y]).find('input.dose').val()) {
                    object['dosage']['type'] = '每次剂量';
                    object['dosage']['value'] = $(medicationTrList[y]).find('input.dose').val();
                } else {
                    object['dosage']['type'] = '分次剂量';
                    object['dosage']['values'] = {};
                    object['dosage']['values']['morning'] = $(medicationTrList[y]).find('input.morning').val();
                    object['dosage']['values']['atnoon'] = $(medicationTrList[y]).find('input.atnoon').val();
                    object['dosage']['values']['evening'] = $(medicationTrList[y]).find('input.evening').val();
                    object['dosage']['values']['before_sleep'] = $(medicationTrList[y]).find('input.sleep').val();
                }
                hpiSub['medication'].push(object);
            }
        }
        //获取 用药 的值  E

        var szGroupId = $('#' + id + ' input.szGroupId').val();
        var url = '/manage/hpiSub/store';
        if (szGroupId) {
            url = '/manage/hpiSub/update';
        }
        hpiSub['id'] = szGroupId;

        hpiSub['record_id'] = record_id;
        szSaveFun(url, hpiSub, id, 'szGroupId');

        generalSituation = true;
    }

    //随诊 组  整理数据  end
    //随诊  保存按钮  start
    $('#suizhen #szSave').click(function () {
        szSaveBtnClick()
    });

    function szSaveBtnClick(NEXT, activeID) {
        if (record_id && record_id != '创建失败') {
            if ((isSzGroupSave()) && generalSituation) {
                szFinishingData(NEXT, activeID);
            }
        } else {
            if ($('input#record_id').val() == '创建失败') {
                $('input#record_id').val('')
            }
            createVisitCase();//创建复诊函数
            var timer = setInterval(function () {
                record_id = $('input#record_id').val();
                if (record_id) {
                    if (record_id == '创建失败') {
                        //alertModel('', '保存失败，请重试！');
                        clearInterval(timer);
                        return false;
                    } else {
                        clearInterval(timer);
                        if ((isSzGroupSave()) && generalSituation) {
                            szFinishingData(NEXT, activeID);
                        }
                    }
                }
            }, 10);
        }
    }

    $('#suizhen #szSaveNext').click(function () {
        // if (record_id && record_id != '创建失败') {
        //     if ((isSzGroupSave()) && generalSituation) {
        //         szFinishingData('next');
        //     }
        // } else {
        //     if ($('input#record_id').val() == '创建失败') {
        //         $('input#record_id').val('')
        //     }
        //     createVisitCase();//创建复诊函数
        //     var timer = setInterval(function () {
        //         record_id = $('input#record_id').val();
        //         if (record_id) {
        //             if (record_id == '创建失败') {
        //                 //alertModel('','保存失败，请重试！');
        //                 clearInterval(timer);
        //                 return false;
        //             } else {
        //                 clearInterval(timer);
        //                 if ((isSzGroupSave()) && generalSituation) {
        //                     szFinishingData('next');
        //                 }
        //             }
        //         }
        //     }, 10);
        // }
        saveNextFun($('#szSave'), $('a[href="#tigejiancha"]'))
    });
    $('#addSzBox button.szGroupSave').click(function () {
        var id = $(this).attr('data-id');
        szGroupData(id);
    });
    //随诊  保存按钮  end
    //随诊保存时 查看是否要对随诊组保存  start
    function isSzGroupSave() {
        var groupDiv = $('#suizhen #addSzBox>div');
        for (var i = 0; i < groupDiv.length; i++) {
            if ($(groupDiv[i]).css('display') == 'block') {
                var time = $(groupDiv[i]).find('div[data-name="started_at"] input').val();
                var symptom = $(groupDiv[i]).find('ul.sui-tag').html().trim();
                var id = $(groupDiv[i]).find('input.szGroupId').val();
                if (time && symptom) {
                    if (!id) {
                        $(groupDiv[i]).find('button.szGroupSave').click();
                    }
                } else {
                    alertModel('', '请填写随诊组的起病日期和起病症状！');
                    return false;
                    break;
                }
            }
        }
        return true;
    }

    //随诊保存时 查看是否要对随诊组保存  end


    var isjump = 0;
    //随诊  监测血糖  start
    $('#monitoringBlood').click(function () {
        if (record_id) {
            window.open("http://www.365tang.cn/datacenter/firstdetail?id=" + record_id);
        } else {
            isjump = 1;
            document.getElementById("szSave").click();
        }
    });
    //随诊  监测血糖  end


    //检查返回数据是否是undefined
    function checkUndefined(data) {
        return (data === undefined || data === null) ? "" : data;

    };


    //保存并下一步处理函数⬇️
    function saveNextFun(saveID, activeID) {
        var selfFun = $(saveID)[0].id + 'BtnClick';
        eval(selfFun)('NEXT', activeID);
    }

});